
#ifndef UTILS_OPENGLCORE
#define UTILS_OPENGLCORE

#include <string>
#include <sstream>
#include <iostream>

#include <glad/glad.h>

static void ClearErrors() {
    while (glGetError()) {}
}

static uint32_t GetErrorCode() {
    return glGetError();
}

static std::string HandleError(const uint32_t errorCode, const char* file, const int line) {
    std::stringstream ss;
    ss << "ErrorCode:" << errorCode << '\n'
        << "File:" << file << '\n'
        << "Line:" << line << '\n';
    return ss.str();
}

#define GLCALL(x) \
    { ClearErrors(); } x; \
    { const auto _errorCode = GetErrorCode(); \
    if (GL_NO_ERROR != _errorCode) std::cout << HandleError(_errorCode, __FILE__, __LINE__) << std::endl; }

#endif // UTILS_OPENGLCORE
